package com.sziit.se.highconcurrency.user.application.controller;


import com.sziit.se.highconcurrency.common.service.IUserService;
import com.sziit.se.highconcurrency.common.annotation.IgnoreCheck;
import com.sziit.se.highconcurrency.common.result.Result;
import com.sziit.se.highconcurrency.common.result.ResultUtil;
import com.sziit.se.highconcurrency.common.tool.PrintThreadInfo;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dongchunkeng
 * @since 2022-09-21
 */
@RestController
@RequestMapping("/application/user")
@AllArgsConstructor
public class UserController {

    private final IUserService userService;

    @GetMapping
    @IgnoreCheck
    public Result getExampleInfo() throws InterruptedException {
        PrintThreadInfo.printThreadInfo();
        return ResultUtil.data(userService.getAllData());
    }

    @PostMapping
    @IgnoreCheck
    public Result addUserInfo(
            @NotBlank(message = "userName为空")String userName,
            @NotBlank(message = "password为空")String password,
            @NotBlank(message = "phone为空")String phone
    ){
        return ResultUtil.auto(userService.insertUser(userName,password, phone));
    }

    @GetMapping
    @IgnoreCheck
    @RequestMapping("/query-by-name")
    public Result getUserByName(@RequestParam(value = "user_name") String userName) throws InterruptedException {
        return ResultUtil.data(userService.getOneData(userName));
    }

    @GetMapping
    @IgnoreCheck
    @RequestMapping("/query-by-id")
    public Result getUserById(@RequestParam(value = "user_id") String userId) throws InterruptedException {

        System.out.println("request in" + userId);
        return ResultUtil.data(userService.getById(userId));
    }
}
